package com.cs.archivesmanagement.fliter;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

import java.util.Map;

/**
 * Created by amo on 2015/8/21.
 */
public class AuthInterceptor extends AbstractInterceptor {


    /**
     *
     * @param actionInvocation
     * @return
     * @throws Exception
     */


    @Override
    public String intercept(ActionInvocation actionInvocation) throws Exception {
        // 取得请求相关的ActionContext实例
        String result = "";
        ActionContext ctx = actionInvocation.getInvocationContext();
        Map session = ctx.getSession();
        String user = (String) session.get("user");
        t("begin");

        if (user != null && "G00100000123".equals(user)) {
            result = actionInvocation.invoke();
        }  else{
            result = "error";
        }
        t("end");
        return result;
    }

    private void t(String s){
        System.out.println(s);
    }
}

